/*
 * File:   Regulator.h
 * Author: Twistx77
 *
 * Created on 22 de junio de 2012, 18:10
 */

#ifndef Regulator_H
#define Regulator_H

#include "aUSBPS.h"
#include "adc.h"
#include "pwm.h"
#include "pps.h"

#define VOLTAGE_DIVIDER_RATIO 100/151.1  // 100K/(100K+51.1K)
#define MAX_OUTPUT_VOLTAGE 500 // 5V*100 which makes it easier to work with two bytes.
#define MAX_OUPUT_CURRENT 450 // Miliamps
#define MAX_OUTPUT_CURRENT_PWM 977 // 450mA @ ADC Input.
#define SHUNT_RESISTOR 140 //Milliohms

#define VOLTAGE_HYSTERESIS 2
#define MAXIMUM_CURRENT_HYSTERESIS 10
#define SET_MAXIMUM_CURRENT_HYSTERESIS 10



void initializeRegulator(void);
void checkOutputStatus(void);
void checkOutputCurrent(void);

void setDesiredOutputVoltageAndCurrent(UINT16 _desiredVoltage, UINT16 _desiredMaximumOutputCurrent);


UINT16 readOutputVoltage(void);
UINT16 readOutputCurrent(void);
UINT16 readSetMaximumOutputCurrent(void);

#endif
